//
//  HWGameCommunityHttpManager.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/10/18.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit
import Alamofire

class HWGameCommunityHttpManager: NSObject {
    var uid = HWLocallyStoredData.getLoginUserID()
    var tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
    var p = 1
    var max_p = "1"
}

extension HWGameCommunityHttpManager {
    /// sign加密
    /// - Returns: sign
    func encrySign() -> String {
        
        let sign = "\(uid)\(tStr)\("fsd213ewdsadqwe2121213edsad")"
        let signMD5 = WMUtil.md5HexDigest(sign) ?? ""
        return signMD5
    }
    func headers() -> HTTPHeaders {
        //        let tStr = Date().timeStamp
        //        let signature = "nnmitu"+tStr
        //
        //        let json = ["usersid":HWLocallyData.getUsersID(),"timestamp":tStr,"signature":signature.DDMD5Encrypt(.lowercase32)]
        //        let jsonString = HWPublicFuncTools.convertDictionAryToJson(dic: json as NSDictionary)
        //        let aesStr:String = aesEncryptString(jsonString, "NrrynIXcpucYvGSk")
        let header:HTTPHeaders = ["eaua":JJUUIDManager.getUUID(),"imei":ASIdentifierManager.shared().advertisingIdentifier.uuidString]
        
        return header
    }
}

extension HWGameCommunityHttpManager {
    
    /// 社区顶部信息
    func getGameCommunityTop(communityId:String,success:@escaping (_ model:HWGameCommunityModel) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":communityId,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GetGameCommunityTop)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWGameCommunityModel.deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model)
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 社区信息
    func getGameCommunityList(communityId:String,type:String,success:@escaping (_ models:[HWGameCommunityListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":communityId,
            "type":type,
            "ios":"1",
            "p":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GetGameCommunityList)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 社区信息
    func getGameCommunityListFooter(communityId:String,type:String,success:@escaping (_ models:[HWGameCommunityListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":communityId,
            "type":type,
            "ios":"1",
            "p":p,
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GetGameCommunityList)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                        self.p -= 1
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    self.p -= 1
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                self.p -= 1
            }
        }
    }
    
    
    /// 详情信息
    @objc func getGameCommunityDetail(newsId:String,success:@escaping (_ model:HWGameCommunityDetailModel) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":newsId,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GetGameCommunityDetail)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWGameCommunityDetailModel.deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model)
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 详情评论列表
    @objc func getGameCommunityDetailComment(newsId:String,success:@escaping (_ models:[HWGameCommunityDetailCommentModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":newsId,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GetGameCommunityDetailComment)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityDetailCommentModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityDetailCommentModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    
    /// 发布文章class_id分类   2攻略  4问题
    func gameCommunityRelease(communityId:String,class_id:String,title:String,content:String,image:String,success:@escaping (_ message:String) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "pid":communityId,
            "class_id":class_id,
            "title":title,
            "content":content,
            "image":image,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityRelease)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        success(resultDic["message"] as? String ?? "")
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 文章点赞type 0 对文章点赞  1 对评论点赞
    @objc func gameCommunityZan(pid:String,puid:String,type:String,success:@escaping (_ message:String) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "pid":pid,
            "puid":puid,
            "type":type,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityZan)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        success(resultDic["message"] as? String ?? "")
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 社区关注
    func gameCommunityFollow(id:String,success:@escaping (_ message:String) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityFollow)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        success(resultDic["message"] as? String ?? "")
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 社区列表$type=0 社区列表，$type=1 社区内的全部社区   $type=2 社区内的我的关注
    func getGameCommunityAllList(type:String,keyword:String,success:@escaping (_ models:[HWGameCommunityAllListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "type":type,
            "keyword":keyword,
            "ios":"1",
            "p":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityAllList)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityAllListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityAllListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 社区列表$type=0 社区列表，$type=1 社区内的全部社区   $type=2 社区内的我的关注
    func getGameCommunityAllListFooter(type:String,keyword:String,success:@escaping (_ models:[HWGameCommunityAllListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "type":type,
            "keyword":keyword,
            "ios":"1",
            "p":p,
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityAllList)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityAllListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityAllListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        self.p-=1
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                        self.p-=1
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    self.p-=1
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                self.p-=1
                //                self.p -= 1
            }
        }
    }
    
    /// 互动消息回复列表
    func getGameCommunityReplyMessage(success:@escaping (_ models:[HWGameCommunityReplyMessageModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "p":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityReplyMessage)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityReplyMessageModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityReplyMessageModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 互动消息回复列表
    func getGameCommunityReplyMessageFooter(success:@escaping (_ models:[HWGameCommunityReplyMessageModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "p":p,
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityReplyMessage)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityReplyMessageModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityReplyMessageModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        self.p-=1
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                        self.p-=1
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    self.p-=1
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                self.p-=1
                //                self.p -= 1
            }
        }
    }
    
    /// 我的帖子列表
    func getGameCommunityInteractPosts(success:@escaping (_ models:[HWGameCommunityListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "p":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityInteractPosts)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 我的帖子列表
    func getGameCommunityInteractPostsFooter(success:@escaping (_ models:[HWGameCommunityListModel]) -> Void, failure:@escaping(_ errorString:String)->Void){
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "p":p,
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunityInteractPosts)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCommunityListModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as! [HWGameCommunityListModel])
                            
                        }else {
                            failure(resultDic["message"] as? String ?? "")
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        self.p-=1
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                        self.p-=1
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    self.p-=1
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                self.p-=1
                //                self.p -= 1
            }
        }
    }
    
    /// 添加评论content 回复内容 pid 文章id 或者评论id (主评论) 子评论也传主评论id type 1 对评论   0 对文章 文章id 或者评论uid， 如果是回复子评论传子评论uid
    @objc func getGameCommunityCommentAdd(pid:String,puid:String,type:String,content:String,success:@escaping (_ nessage:String) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "pid":pid,
            "puid":puid,
            "content":content,
            "type":type,
            "ios":"1",
            "p":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunitCommentAdd)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(resultDic["message"] as? String ?? "")
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 删除文章
    func gameCommunityCommentDel(id:String,success:@escaping (_ nessage:String) -> Void, failure:@escaping(_ errorString:String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "ios":"1",
            "p":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_CommunitDelete)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(resultDic["message"] as? String ?? "")
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
}


